/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qual2009;

import java.util.Queue;
import java.util.LinkedList;
import java.io.IOException;
import javax.sound.midi.Soundbank;
import static chanlib.Chan_IO.*;

/**
 * @author robit
 */
public class Watersheds{
    /*
      All neccesary to be defined
      including:
      variable, inner class
    */
    // static int A;
    // static void B();
    // static class C

    /*
       One calculation fits all of the cases.
    */
    static void preReckon(){
        return;
    }
    final static int SINK=0,NORTH=1,WEST=2,EAST=3,SOUTH=4;
    static int opposite(int dir){
        switch(dir){
            case NORTH: return SOUTH;
            case WEST: return EAST;
            case EAST: return WEST;
            case SOUTH: return NORTH;
        }
        return 0;
    }
    /*
      calculate the answer
    */
    private static void reckon(int line) {
        int H=Int();
        int W=Int();
        int [][] alt=new int[H][W];
        for(int i=0;i<H;i++)
            for(int j=0;j<W;j++)
                alt[i][j]=Int();

        int [][] flowDir=new int[H][W];
        
        int di[]={0,-1,0,0,1};
        int dj[]={0,0,-1,1,0};
        for(int i=0;i<H;i++)
        for(int j=0;j<W;j++){
            int lowest=alt[i][j];
            for(int dir=1;dir<=SOUTH;dir++){
                int ii=i+di[dir],jj=j+dj[dir];
                if(ii<0||ii>=H||jj<0||jj>=W)continue;
                if(alt[ii][jj]<lowest){
                    lowest=alt[ii][jj];
                    flowDir[i][j]=dir;
                }
            }
           
        }
         //int no=7;
        class Pair{
            int i, j;
            public Pair(int i, int j) {
                this.i = i;
                this.j = j;
            }
        }
        
        boolean checked[][] = new boolean[H][W];
        Queue<Pair> bfs = new LinkedList<Pair>();
        //StringBuilder rep = new StringBuilder();//test
        char label='a';
        char labeled[][]=new char[H][W];
        for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
        {
            if (checked[i][j]) {
                continue;
            }
            checked[i][j] = true;
            bfs.add(new Pair(i,j));
            while (!bfs.isEmpty()) {
                Pair h = bfs.poll();
                if (h == null) {
                    break;
                }
                labeled[h.i][h.j]=label;
                //rep.append(' ').append(h);//test
                for(int dir=1;dir<=SOUTH;dir++){
                    int ii=h.i+di[dir],jj=h.j+dj[dir];
                    if(ii<0||ii>=H||jj<0||jj>=W)continue;
                    if(checked[ii][jj])continue;
                    if(flowDir[h.i][h.j]!=dir && flowDir[ii][jj]!=opposite(dir))
                        continue;
                    checked[ii][jj]=true;
                    bfs.add(new Pair(ii, jj));
                }
//                for (int t = 0; t < N; t++) {
//                    if (checked[t] || adj[h][t] == 0) {
//                        continue;
//                    }
//                    checked[t] = true;
//                    bfs.add(t);
//                }
            }
            bfs.clear();
            label++;
            //System.out.println(rep);//test
            //rep.delete(0, rep.length());//test
        }
        
        StringBuilder ans =new StringBuilder();

        String output=String.format("Case #%d:",line);
        writeln(output, OUTFILE);
        for(int i=0;i<H;i++){
            ans.delete(0, ans.length());
            for(int j=0;j<W;j++){
                ans.append(labeled[i][j]).append(" ");
            }
            writeln(ans.toString(), OUTFILE);
        }

        // writeln(String.format("N=%d K=%d\n%s", N, K, ans),ANALFILE);
        //println(output);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        /*
           Pre-computing for all cases
        */

        // Just in case!
        //preReckon();
        //while((char)read()!='P');

        /*
          Input-output
        */
        boolean test=false;
        boolean small=false;
        String prob="B";
        String filename;
        if(test) filename="test";
        else{
            if(small) filename=prob+"-small-practice";
            else filename=prob+"-large-practice";
        }
        try {
            /*
               Init IO,plus determination of input line number
             */
            int lineNums = initFileIO(filename);
            for (int i = 1; i <= lineNums; i++) {
                reckon(i);
            }
        } finally {
            endIO();
        }
    }

}
